﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Artech.Core
{
    /// <summary>
    /// Interface defining the behavior of the service locator.
    /// </summary>
    public interface IServiceLocator
    {
        /// <summary>
        /// Gets the service instance based on the given type and name.
        /// </summary>
        /// <param name="serviceType">The service registration type.</param>
        /// <param name="key">The registration key.</param>
        /// <returns>The service instance.</returns>
        object GetService(Type serviceType, string key = "");

        /// <summary>
        /// Gets the service instance based on name.
        /// </summary>
        /// <typeparam name="T">The service registration type.</typeparam>
        /// <param name="key">The registration key.</param>
        /// <returns>The service instance.</returns>
        T GetService<T>(string key = "");

        /// <summary>
        /// Gets all services instances based on type and name.
        /// </summary>
        /// <param name="serviceType">The service registration type.</param>
        /// <param name="key">The registration key.</param>
        /// <returns>The service instance list.</returns>
        IEnumerable GetAllServices(Type serviceType, params string[] keys);

        /// <summary>
        /// Determines whether the service instance can be located based on the given type and registration name.
        /// </summary>
        /// <typeparam name="T">The service type.</typeparam>
        /// <param name="key">The registration key.</param>
        /// <returns>
        ///   <c>true</c> if the service can be located; otherwise, <c>false</c>.
        /// </returns>
        bool CanLocateService<T>(string key = "");

        /// <summary>
        /// Gets all services instances based on and name.
        /// </summary>
        /// <typeparam name="T">The service registration type.</typeparam>
        /// <param name="keys">The registration key.</param>
        /// <returns>
        /// The service instance list.
        /// </returns>
        IEnumerable<T> GetAllServices<T>(params string[] keys);

        /// <summary>
        /// Releases the service instance.
        /// </summary>
        /// <param name="service">The service instance.</param>
        void ReleaseService(object service);
    }
}
